import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/assets/styles.dart';
import 'package:pornhub_app/components/image_view.dart';
import 'package:pornhub_app/components/text_view.dart';
import 'package:pornhub_app/generate/app_image_path.dart';
import 'package:pornhub_app/model/activity/super_activity_model.dart';
import 'package:pornhub_app/routes/routes.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/utils/extension.dart';
// ignore: unused_import
import 'package:pornhub_app/utils/m3u8_download/m3u8_downloader_manager.dart';

class ActivityCell extends StatelessWidget {
  final SuperActivityModel activity;
  final int index;
  const ActivityCell({super.key, required this.activity, required this.index});

  @override
  Widget build(BuildContext context) {
    _buildAvatarItems() {
      List<Widget> widgets = [];
      // int index = 0;
      int len = activity.participants?.length ?? 0;
      widgets.add(SizedBox(
        width: 20.w,
        height: 20.w,
      ));
      for (int i = 0; i < len; i++) {
        widgets.add(Positioned(
            left: (i * 16).w,
            child: Container(
              decoration: BoxDecoration(
                border: Border.all(color: COLOR.white),
                borderRadius: BorderRadius.circular(20.w),
              ),
              child: ImageView(
                src: activity.participants![i].logo ?? "",
                width: 20.w,
                height: 20.w,
                borderRadius: BorderRadius.circular(20.w),
              ),
            )));
      }
      widgets.add(Positioned(
          left: (len * 16.w) + 12.w,
          child: TextView(
            text: "${activity.currentParticipants}人已报名",
            style: kTextStyle(COLOR.color_EBEBEB, fontsize: 12.w),
          ).paddingTop(2.w)));
      return widgets;
    }

    return Stack(
      children: [
        Container(
          width: 372.w,
          padding:
              EdgeInsets.only(top: 8.w, bottom: 8.w, left: 7.w, right: 7.w),
          margin: EdgeInsets.only(bottom: 15.w),
          decoration: BoxDecoration(
              color: COLOR.color_181818,
              borderRadius: BorderRadius.circular(4.w)),
          child: Row(
            children: [
              ImageView(
                src: activity.coverImg ?? "",
                width: 120.w,
                height: 120.w,
                borderRadius: BorderRadius.circular(8.w),
              ),
              Expanded(
                  child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  TextView(
                    text: "${activity.activityName}",
                    style: kTextStyle(COLOR.white, fontsize: 14.w),
                  ),
                  Container(
                    height: 20.w,
                    width: 372.w,
                    margin: EdgeInsets.only(top: 4.w, bottom: 9.w),
                    child: ListView.builder(
                        itemCount: activity.tags?.length,
                        scrollDirection: Axis.horizontal,
                        shrinkWrap: true,
                        itemBuilder: (ctx, index) {
                          return Container(
                            alignment: Alignment.center,
                            margin: EdgeInsets.only(right: 8.w),
                            padding: EdgeInsets.only(left: 8.w, right: 8.w),
                            decoration: BoxDecoration(
                                color: COLOR.color_333333,
                                borderRadius: BorderRadius.circular(10.w)),
                            child: TextView(
                              text: "${activity.tags![index]}",
                              style: kTextStyle(COLOR.white, fontsize: 11.w),
                            ),
                          );
                        }),
                  ),
                  Row(
                    children: [
                      ImageView(
                        src: AppImagePath.activity_activity_time,
                        width: 14.w,
                        height: 14.w,
                      ),
                      TextView(
                        text: "${activity.activityDate}",
                        style: kTextStyle(COLOR.white, fontsize: 12.w),
                      ).paddingLeft(4.w)
                    ],
                  ),
                  Row(
                    children: [
                      ImageView(
                        src: AppImagePath.activity_activity_location,
                        width: 12.w,
                        height: 15.w,
                      ),
                      TextView(
                        text: "${activity.location}",
                        style: kTextStyle(COLOR.white, fontsize: 12.w),
                      ).paddingLeft(4.w)
                    ],
                  ).marginOnly(top: 6.w, bottom: 4.w),
                  if (activity.currentParticipants != 0)
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      mainAxisSize: MainAxisSize.max,
                      children: [
                        Stack(
                          clipBehavior: Clip.none,
                          children: _buildAvatarItems(),
                        ),
                      ],
                    )
                ],
              ).paddingLeft(8.w)),
            ],
          ),
        ),
        if (activity.status == 0)
          Positioned(
              right: 3.w,
              bottom: 18.w,
              child: Container(
                width: 64.w,
                height: 27.w,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    border: Border.all(color: COLOR.color_B940FF),
                    borderRadius: BorderRadius.circular(14.w)),
                child: TextView(
                  text: "去报名",
                  style: kTextStyle(COLOR.color_B940FF, fontsize: 12.w),
                ),
              ))
        else ...[
          if (activity.status == 1)
            Positioned(
                right: 3.w,
                bottom: 18.w,
                child: ImageView(
                  src: AppImagePath.activity_activity_full,
                  width: 45.w,
                  height: 42.5.w,
                )),
          if (activity.status == 2)
            Positioned(
                right: 3.w,
                bottom: 18.w,
                child: ImageView(
                  src: AppImagePath.activity_activity_end,
                  width: 45.w,
                  height: 42.5.w,
                ))
        ]
      ],
    ).onOpaqueTap(() {
      Get.toActivityDetail(activity.activityId ?? 0);
    });
  }
}
